package org.jing.core.lang.data;

import org.jing.core.util.ClassUtil;

import java.math.BigDecimal;

/**
 * Description: 累加器 <br>
 *
 * @author bksmate <br>
 * @since 2025-07-07 <br>
 */
@SuppressWarnings("unused")
public class Accumulator {
    private int count = 0;

    private BigDecimal sum = BigDecimal.ZERO;

    public Accumulator() {}

    public Accumulator(int count, BigDecimal sum) {
        this.count = count;
        this.sum = sum;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public BigDecimal getSum() {
        return sum;
    }

    public void setSum(BigDecimal sum) {
        this.sum = sum;
    }

    public void increment(Object value) {
        count ++;
        sum = sum.add(ClassUtil.cast2Number(value));
    }

    public void decrement(Object value) {
        count --;
        sum = sum.subtract(ClassUtil.cast2Number(value));
    }
}
